Socket
Socket
Sign inDemoInstall

natural-compare

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

natural-compare

Compare strings containing a mix of letters and numbers in the way a human being would in sort order.


Version published
Weekly downloads
32M
decreased by-6.41%
Maintainers
1
Weekly downloads
 
Created

What is natural-compare?

The natural-compare npm package provides a simple way to perform 'natural' string comparisons. This means it can compare strings in a way that is more intuitive for humans, taking into account numerical values within the strings to order them in a way that makes sense when read. For example, it would order 'item2' before 'item10', which is not the case with traditional ASCII-based string comparison methods.

What are natural-compare's main functionalities?

Natural String Comparison

This feature allows for the comparison of strings containing numerical values in a way that respects the numerical values, rather than comparing them purely as strings. The provided code sample demonstrates sorting an array of strings in a natural order using the package.

"use strict";
var naturalCompare = require('natural-compare');
console.log(['item10', 'item2'].sort(naturalCompare)); // ['item2', 'item10']

Other packages similar to natural-compare

Keywords

FAQs

Package last updated on 22 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc